package com.neu.entity;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.neu.base.BaseEntity;
import com.neu.utils.ExcelReader;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.*;

@Schema(description = "软件生产率")
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("project_pdr")
public class PDR extends BaseEntity {

    @TableId(type= IdType.ASSIGN_ID)
    private String projectId;

    private boolean history;//是否采用历史数据
    private String historyPath;//历史数据URL
    private Float pdr;
    private int progress;//0代表未完成、1代表已完成

    public int getProgress() {
        return progress;
    }

    public void setProgress(int progress) {
        this.progress = progress;
    }

    public void setPdr(Float pdr) {
        this.pdr = pdr;
    }

    public Map CalcPDR(){
        Map pdr_pack = new HashMap<>();
        ArrayList<Float> h_list = null;

        float pdr;
        if (this.history){
            h_list = (ArrayList<Float>) ExcelReader.readHistory(this.historyPath);
            Collections.sort(h_list);
            int p = 1 - h_list.size() % 2;

            int p50_i = h_list.size() / 2;
            int p50_j = h_list.size() / 2 - p;

            pdr = (h_list.get(p50_i) + h_list.get(p50_j)) / 2;
            pdr_pack.put("pdr", pdr);
        }else{
            pdr_pack.put("pdr", 7.01f);
        }

        this.pdr = (Float) pdr_pack.get("pdr");

        return pdr_pack;
    }

    @Override
    public String toString() {
        return "PDR{" +
                "projectId='" + projectId + '\'' +
                ", history=" + history +
                ", historyPath='" + historyPath + '\'' +
                ", pdr=" + pdr +
                ", progress=" + progress +
                '}';
    }
}
